package org.wanho.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Author：汤小洋
 * Date：2024-12-02 15:52
 * Description：<描述>
 */
@WebServlet("/login")
public class LoginServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取请求中的参数
        req.setCharacterEncoding("utf8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String method = req.getMethod();
        System.out.println(method);

        try {
            Thread.sleep(5000); // 休眠
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        resp.setContentType("text/html;charset=utf8");
        PrintWriter out = resp.getWriter();

        if("admin".equals(username)  && "123".equals(password)){
            out.print("<h2>登录成功！</h2>");
        }else{
            out.print("<h2>登录失败！</h2>");
        }
        out.close();
    }
}
